using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace Report.PhieuA
{
    public partial class UcPhieuA1 : DevExpress.XtraEditors.XtraUserControl
    {
        public UcPhieuA1()
        {
            InitializeComponent();
        }

        private void UcPhieuA1_Load(object sender, EventArgs e)
        {
            DataTable dtA1 = new DsReportX.Table4ColDataTable();
            gridControlA.DataSource = dtA1;
            CalculateData(dtA1);
        }

        DataTable CalculateData(DataTable dt)
        {
            SqlConnection con = new SqlConnection(GeneralLibs.LocalSettings.ConnectString);
            SqlCommand cmd = con.CreateCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                con.Open();
                cmd.CommandText = "SELECT SUM(Number1) number1,SUM(Number2) number2,SUM(Number3)number3,SUM(Number4)number4 \n" +
                                "FROM Phieu_DangBang A INNER JOIN Phieu B ON A.PhieuID = B.ID \n" +
                                "WHERE LoaiPhieu = 'PhieuA' AND MaCau = 9 AND ThuTuTrongBang <> 1  \n" +
                                "GROUP BY ThuTuTrongBang   \n";
                da.SelectCommand = cmd;
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
